package com.doyens.controller;

import com.alibaba.druid.util.StringUtils;
import com.doyens.pojo.Applicant;
import com.doyens.service.ApplicantService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/applicant")
public class ApplicantController {

    @Autowired
    private ApplicantService applicantService;

//    列表展示带分页
    @RequestMapping("/list.do")
    @ResponseBody
    public PageInfo<Applicant> pageList(Integer page,Integer pageSize) throws IOException {
        PageInfo<Applicant> pb = applicantService.list(page,pageSize);
        return pb;
    }

    /**
     * 动态展示状态栏的下拉菜单
     * @return
     */
    @RequestMapping("/findStatus.do")
    @ResponseBody
    public List<Applicant> findStatus(){
        List<Applicant> status = applicantService.findStatus();
        return status;
    }

    /**
     * 动态展示下拉选框，学历菜单
     */
    @RequestMapping("/findEducation.do")
    @ResponseBody
    public List<Applicant> findEducation(){
        List<Applicant> educations = applicantService.findEducation();
//        System.out.println(educations);
        return educations;
    }

    /**
     * 根据id查询应聘者，回显数据
     */
    @RequestMapping("/findById.do")
    @ResponseBody
    public Applicant findById(String id){
        Applicant applicant = applicantService.findById(id);
//        System.out.println(applicant);
        return applicant;
    }

    /**
     * 修改后存储应聘者信息
     */
    @RequestMapping("/saveEdit.do")
    @ResponseBody
    public Integer saveEdit(Applicant applicant,Integer[] interviewerIds){
        return applicantService.saveEdit(applicant,interviewerIds);
    }

    /**
     * 多条件模糊查询
     * 在业务层判断参数
     */
    @RequestMapping("/findByCondition.do")
    @ResponseBody
    public List<Applicant> findByCondition(String ename,Integer status){
        return applicantService.findByCondition(ename,status);
    }

    /**
     * 根据id删除单条数据
     */
    @RequestMapping("/del.do")
    @ResponseBody
    public Integer delete(Integer eid){
        return applicantService.del(eid);
    }

    /**
     * 多选删除
     */
    @RequestMapping("/dels.do")
    @ResponseBody
    public Integer dels(Integer[] eids){
        Integer i = 0;
        for (Integer eid : eids) {
           i = applicantService.del(eid);
        }
        return i;
    }
}
